package com.zhiyou.wisdom.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zhiyou.wisdom.pojo.Visitor;
import com.zhiyou.wisdom.service.VisitorService;

@RestController
@RequestMapping(value="/wisdom")
public class VisitorController {
	@Autowired
	VisitorService visitorService;
	
	@GetMapping(value="/getVisitorById/{v_id}")
	public Visitor getVisitorById(@PathVariable Integer v_id){
//		System.out.println(v_id);
		return visitorService.selectByPrimaryKey(v_id);
	}
	
	/**
	 * 当天来访情况
	 * 根据不同情况查询
	 * @param flag   1:查询当天  2：查询本周   3：查询当月
	 * @return
	 */
	@GetMapping(value="/getVisitorByFlag/{flag}")
	public Map<String, Object> getVisitorsByFlag(@PathVariable Integer flag){
//		System.out.println(flag);
		return visitorService.selectByParams(flag);
	}
	
	/**
	 * 申请情况
	 * 根据不同的参数返回不同的数据
	 * @param flag 1:未审配   2:已审批   3:全部
	 * @return
	 */
	@GetMapping(value="/getVisitorByAudit/{flag}")
	public Map<String, Object> selectByAudit(@PathVariable Integer flag){
//		System.out.println(flag);
		return visitorService.selectByAudit(flag);
	}
	
	
	/**
	 * 黑名单预警未实现
	 * 调用公安系统第三方接口，未实现
	 */
	
	
	/**
	 * 添加预约信息
	 * @param visitor
	 * @return
	 */
	@GetMapping(value="/addVisitor")
	public int addOrderVisitor(Visitor visitor){
		//添加返回受影响的行数
		int count=visitorService.insert(visitor);
		return count;
	}
	
	
	
	/** 
	 * 注册时间类型的属性编辑器，将String转化为Date 
	 */  
	@InitBinder  
	public void initBinder(ServletRequestDataBinder binder) {  
	    binder.registerCustomEditor(Date.class, new CustomDateEditor(  
	            new SimpleDateFormat("yyyy-MM-dd"), true));  
	}  
	
	
}
